
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>线程的创建与生命周期 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>线程的创建与生命周期 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在Java中，创建线程的两种常用方式是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">1. 继承`Thread`类并重写`run()`方法。2. 实现`Runnable`接口，并将其对象传递给`Thread`的构造器来创建线程。</div>
          </div>
          <div class="card-source">来源: 1. 线程的创建方式概述</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">调用线程的`start()`方法和直接调用`run()`方法有何根本区别？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">调用`start()`方法会使线程进入“就绪”状态，并由JVM调度执行`run()`方法，这才是真正的启动一个新线程。而直接调用`run()`方法只是在当前线程中执行一个普通方法，并不会启动新线程。</div>
          </div>
          <div class="card-source">来源: 5. start()与run()方法的执行流程</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">根据`Thread.State`枚举，Java线程生命周期包含哪些主要状态？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">主要状态包括：新建 (New)、就绪 (Runnable)、运行 (Running)、阻塞 (Blocked)、等待 (Waiting)、定时等待 (Timed Waiting) 和 死亡 (Terminated)。</div>
          </div>
          <div class="card-source">来源: 4. 线程生命周期的各个状态</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">一个处于“新建”(New)状态的线程是如何转换到“就绪”(Runnable)状态的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">通过调用该线程的`start()`方法，线程会从“新建”状态进入“就绪”状态，等待CPU调度执行。</div>
          </div>
          <div class="card-source">来源: 4. 线程生命周期的各个状态</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">通过实现`Runnable`接口创建线程时，如何将任务逻辑（Runnable实例）与线程（Thread实例）关联起来？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">将实现了`Runnable`接口的对象传递给`Thread`类的构造器，从而创建一个新的`Thread`对象。</div>
          </div>
          <div class="card-source">来源: 3. 实现Runnable接口的线程创建</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">当对一个正在执行`sleep()`或`wait()`方法的线程调用`interrupt()`方法时，会发生什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">该线程会抛出`InterruptedException`异常，从而中断其阻塞或等待状态。</div>
          </div>
          <div class="card-source">来源: 7. 线程的中断与停止</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">文档中提到了哪三种常见的导致线程进入阻塞或等待状态的原因？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">1. 等待同步锁（例如进入`synchronized`块）。 2. 调用`Object.wait()`方法进入等待状态。 3. 调用`Thread.sleep()`方法进入定时等待状态。</div>
          </div>
          <div class="card-source">来源: 6. 线程的阻塞与唤醒</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">线程何时会进入“死亡”(Terminated)状态？处于此状态的线程还能再次被启动吗？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当线程执行完其`run()`方法后，就会进入“死亡”状态。进入此状态后，线程无法再次被启动。</div>
          </div>
          <div class="card-source">来源: 8. 线程的死亡与资源释放</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">一个因调用`wait()`方法而进入等待状态的线程，需要通过什么方式被唤醒？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">需要由其他线程调用同一个对象上的`notify()`或`notifyAll()`方法来唤醒它。</div>
          </div>
          <div class="card-source">来源: 6. 线程的阻塞与唤醒</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
